package com.aldobucchi.utils
{
	import flash.events.EventDispatcher;
	
	import com.aldobucchi.core.comparison.simple.ISimpleComparable;
	import com.aldobucchi.core.comparison.result.ComparisonResult;
	import com.aldobucchi.core.comparison.result.ComparisonResults;
	
	
	public class MediaType extends EventDispatcher implements ISimpleComparable
	{
		
		public static const ALL
			:MediaType = register( "*/*", "All" );
		
		public static const _application
			:MediaType = register( "application/*", "Application" );
			
		public static const _application_x_java_serialized_object
			:MediaType = register( "application/x-java-serialized-object", "Serialized Java Object" );
		
		public static const _application_pdf
			:MediaType = register( "application/pdf", "Adobe Acrobat Document" );
		
		
		// application/sparql-results+json
		
		
		
		
		
		
		
		
		
	
	
	
	
	
	
	
	
	
		private var _name:String;
		[Bindable("change")]// just to elimitate binding warnings
		public function get name():String
		{
			return _name
		}
		
		private var _description:String;
		[Bindable("change")]// just to elimitate binding warnings
		public function get description():String
		{
			return _description;
		}
		
		private var _parameters:Array = [];
		[Bindable("change")]// just to elimitate binding warnings
		public function get parameters():Array
		{
			return parameters;
		}
	
	
		// private
		public function MediaType( name:String, description:String, parameters:Array = null )
		{
			_name = name;
			_description = description;
			
			if ( parameters != null )
				_parameters = parameters;
		}
		
		
		
		
		
		
		public function compare( other:* ):ComparisonResult
		{
			if ( other === this )	return ComparisonResults.EQUAL; 
			
			var o:MediaType = other as MediaType;
			if ( o == null ) 		return ComparisonResults.DIFFERENT;
			if ( o == this )		return ComparisonResults.EQUAL;
			if ( o.name != name )	return ComparisonResults.DIFFERENT;
			
			return ComparisonResults.EQUAL;
		}
		
		
		
		
		
		private static var registeredMediaTypes:Array = [];
		public static function register( name:String, description:String, parameters:Array = null ):MediaType
		{
			var mediaType:MediaType = new MediaType( name, description, parameters );
			registeredMediaTypes.push( mediaType );
			return mediaType;					
		}
		
	}
}

/*
 
          case ALL:
            result = "*//*";
            break;
         case APPLICATION_ALL:
            result = "application/*";
            break;
         case APPLICATION_HTTP_COOKIES:
            result = "application/x-http-cookies"; // Guessed!
            break;
         case APPLICATION_JAVA_OBJECT:
            result = "application/x-java-serialized-object";
            break;
         case APPLICATION_PDF:
            result = "application/pdf";
            break;
         case APPLICATION_WORD:
            result = "application/msword";
            break;
         case APPLICATION_WWW_FORM:
            result = "application/x-www-form-urlencoded";
            break;
         case APPLICATION_XHTML_XML:
            result = "application/xhtml+xml";
            break;
         case APPLICATION_XML:
            result = "application/xml";
            break;
         case APPLICATION_ZIP:
            result = "application/zip";
            break;
         case IMAGE_ALL:
            result = "image/*";
            break;
         case IMAGE_GIF:
            result = "image/gif";
            break;
         case IMAGE_ICON:
            result = "image/x-icon";
            break;
         case IMAGE_PNG:
            result = "image/png";
            break;
         case TEXT_ALL:
            result = "text/*";
            break;
         case TEXT_CSS:
            result = "text/css";
            break;
         case TEXT_HTML:
            result = "text/html";
            break;
         case TEXT_PLAIN:
            result = "text/plain";
            break;
         case TEXT_URI:
            result = "text/uri";
            break;
         case TEXT_XML:
            result = "text/xml";
            break;
 
 
 
 
 
 
 http://fisheye3.cenqua.com/browse/~raw,r=364/restlet/trunk/source/main/com/noelios/restlet/impl/MediaTypeImpl.java
 
 
 
 */